﻿Imports System.Data.Common
Imports System.Drawing
Imports Microsoft.Office.Interop.Word
Imports stdole

Module myFunc
    Public oWord = Globals.Ribbons.Ribbon1.oWord
    Public Sub SetMyStyle(Type As String)
        With oWord.Selection.ParagraphFormat
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("AddSpaceBetweenFarEastAndAlpha") = .AddSpaceBetweenFarEastAndAlpha
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("AddSpaceBetweenFarEastAndDigit") = .AddSpaceBetweenFarEastAndDigit
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("Alignment") = .Alignment
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("AutoAdjustRightIndent") = .AutoAdjustRightIndent
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("BaseLineAlignment") = .BaseLineAlignment
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("CharacterUnitFirstLineIndent") = .CharacterUnitFirstLineIndent
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("CharacterUnitLeftIndent") = .CharacterUnitLeftIndent
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("CharacterUnitRightIndent") = .CharacterUnitRightIndent
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("CollapsedByDefault") = .CollapsedByDefault
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("DisableLineHeightGrid") = .DisableLineHeightGrid
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("FarEastLineBreakControl") = .FarEastLineBreakControl
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("FirstLineIndent") = .FirstLineIndent
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("HalfWidthPunctuationOnTopOfLine") = .HalfWidthPunctuationOnTopOfLine
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("HangingPunctuation") = .HangingPunctuation
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("Hyphenation") = .Hyphenation
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("KeepTogether") = .KeepTogether
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("KeepWithNext") = .KeepWithNext
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("LeftIndent") = .LeftIndent
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("LineSpacing") = .LineSpacing
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("LineSpacingRule") = .LineSpacingRule
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("LineUnitAfter") = .LineUnitAfter
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("LineUnitBefore") = .LineUnitBefore
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("MirrorIndents") = .MirrorIndents
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("NoLineNumber") = .NoLineNumber
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("OutlineLevel") = .OutlineLevel
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("PageBreakBefore") = .PageBreakBefore
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("ReadingOrder") = .ReadingOrder
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("RightIndent") = .RightIndent
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("Shading").item（"BackgroundPatternColor") = .Shading.BackgroundPatternColor
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("Shading").item（"BackgroundPatternColorIndex") = .Shading.BackgroundPatternColorIndex
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("Shading").item（"ForegroundPatternColor") = .Shading.ForegroundPatternColor
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("Shading").item（"ForegroundPatternColorIndex") = .Shading.ForegroundPatternColorIndex
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("Shading").item（"Texture") = .Shading.Texture
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("SpaceAfter") = .SpaceAfter
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("SpaceAfterAuto") = .SpaceAfterAuto
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("SpaceBefore") = .SpaceBefore
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("SpaceBeforeAuto") = .SpaceBeforeAuto
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("Style") = .Style
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("TabStops") = .TabStops
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("TextboxTightWrap") = .TextboxTightWrap
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("WidowControl") = .WidowControl
            Globals.Ribbons.Ribbon1.obj.item(Type).item("段落").item("WordWrap") = .WordWrap
        End With

        With oWord.Selection.Font
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("AllCaps") = .AllCaps
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Bold") = .Bold
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("BoldBi") = .BoldBi
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("ColorIndex") = .ColorIndex
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("ColorIndexBi") = .ColorIndexBi
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("ContextualAlternates") = .ContextualAlternates
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("DiacriticColor") = .DiacriticColor
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("DisableCharacterSpaceGrid") = .DisableCharacterSpaceGrid
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("DoubleStrikeThrough") = .DoubleStrikeThrough
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Emboss") = .Emboss
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("EmphasisMark") = .EmphasisMark
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Engrave") = .Engrave
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Hidden") = .Hidden
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Italic") = .Italic
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("ItalicBi") = .ItalicBi
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Kerning") = .Kerning
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Ligatures") = .Ligatures
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Name") = .Name
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("NameAscii") = .NameAscii
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("NameFarEast") = .NameFarEast
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("NameOther") = .NameOther
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("NumberForm") = .NumberForm
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("NumberSpacing") = .NumberSpacing
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Outline") = .Outline
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Position") = .Position
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Scaling") = .Scaling
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Shading").item("BackgroundPatternColor") = .Shading.BackgroundPatternColor
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Shading").item("BackgroundPatternColorIndex") = .Shading.BackgroundPatternColorIndex
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Shading").item("ForegroundPatternColor") = .Shading.ForegroundPatternColor
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Shading").item("ForegroundPatternColorIndex") = .Shading.ForegroundPatternColorIndex
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Shading").item("Texture") = .Shading.Texture
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Shadow") = .Shadow
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Size") = .Size
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("SizeBi") = .SizeBi
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("SmallCaps") = .SmallCaps
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Spacing") = .Spacing
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("StrikeThrough") = .StrikeThrough
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Subscript") = .Subscript
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("Underline") = .Underline
            Globals.Ribbons.Ribbon1.obj.item(Type).item("字体").item("UnderlineColor") = .UnderlineColor
        End With
    End Sub
    Public Sub 保存页码配置()
        Dim returnValue = MsgBox("确认将页码格式设置为当前页码样式？", vbOKCancel + vbExclamation + vbDefaultButton2, "")
        If returnValue = 1 Then
            With oWord.ActiveDocument.Sections(1).Footers(WdHeaderFooterIndex.wdHeaderFooterPrimary)
                Globals.Ribbons.Ribbon1.obj.item("页码"）.item("style"） = .PageNumbers.NumberStyle   '页码风格
            End With
            Globals.Ribbons.Ribbon1.保存配置（）
        End If
    End Sub

    Public Sub 保存公文标题配置()
        Dim returnValue = MsgBox("确认将公文标题格式设置为当前选中文本样式？", vbOKCancel + vbExclamation + vbDefaultButton2, "")
        If returnValue = 1 Then
            SetMyStyle("公文标题")
            Globals.Ribbons.Ribbon1.保存配置（）
        End If
    End Sub

    Public Sub 保存二级标题配置()
        Dim returnValue = MsgBox("确认将二级标题格式设置为当前选中文本样式？", vbOKCancel + vbExclamation + vbDefaultButton2, "")
        If returnValue = 1 Then
            SetMyStyle("二级标题")
            Globals.Ribbons.Ribbon1.保存配置（）
        End If
    End Sub
    Public Sub 保存三级标题配置()
        Dim returnValue = MsgBox("确认将三级标题格式设置为当前选中文本样式？", vbOKCancel + vbExclamation + vbDefaultButton2, "")
        If returnValue = 1 Then
            SetMyStyle("三级标题")
            Globals.Ribbons.Ribbon1.保存配置（）
        End If
    End Sub

    Public Sub 保存小行间距配置()
        Dim returnValue = MsgBox("确认将小行间距设置为当前选中文本样式？", vbOKCancel + vbExclamation + vbDefaultButton2, "")
        If returnValue = 1 Then
            With oWord.Selection.ParagraphFormat
                Globals.Ribbons.Ribbon1.obj.item("小行间距").item("CharacterUnitLeftIndent") = .CharacterUnitLeftIndent
                Globals.Ribbons.Ribbon1.obj.item("小行间距").item("CharacterUnitRightIndent") = .CharacterUnitRightIndent
                Globals.Ribbons.Ribbon1.obj.item("小行间距").item("LineSpacing") = .LineSpacing
                Globals.Ribbons.Ribbon1.obj.item("小行间距").item("LineSpacingRule") = .LineSpacingRule
                Globals.Ribbons.Ribbon1.obj.item("小行间距").item("LeftIndent") = .LeftIndent
                Globals.Ribbons.Ribbon1.obj.item("小行间距").item("RightIndent") = .RightIndent
                Globals.Ribbons.Ribbon1.obj.item("小行间距").item("LineUnitAfter") = .LineUnitAfter
                Globals.Ribbons.Ribbon1.obj.item("小行间距").item("LineUnitBefore") = .LineUnitBefore
                Globals.Ribbons.Ribbon1.obj.item("小行间距").item("SpaceAfter") = .SpaceAfter
                Globals.Ribbons.Ribbon1.obj.item("小行间距").item("SpaceBefore") = .SpaceBefore
            End With
            Globals.Ribbons.Ribbon1.保存配置（）
        End If
    End Sub
    Public Sub 保存中行间距配置()
        Dim returnValue = MsgBox("确认将中行间距设置为当前选中文本样式？", vbOKCancel + vbExclamation + vbDefaultButton2, "")
        If returnValue = 1 Then
            With oWord.Selection.ParagraphFormat
                Globals.Ribbons.Ribbon1.obj.item("中行间距").item("CharacterUnitLeftIndent") = .CharacterUnitLeftIndent
                Globals.Ribbons.Ribbon1.obj.item("中行间距").item("CharacterUnitRightIndent") = .CharacterUnitRightIndent
                Globals.Ribbons.Ribbon1.obj.item("中行间距").item("LineSpacing") = .LineSpacing
                Globals.Ribbons.Ribbon1.obj.item("中行间距").item("LineSpacingRule") = .LineSpacingRule
                Globals.Ribbons.Ribbon1.obj.item("中行间距").item("LeftIndent") = .LeftIndent
                Globals.Ribbons.Ribbon1.obj.item("中行间距").item("RightIndent") = .RightIndent
                Globals.Ribbons.Ribbon1.obj.item("中行间距").item("LineUnitAfter") = .LineUnitAfter
                Globals.Ribbons.Ribbon1.obj.item("中行间距").item("LineUnitBefore") = .LineUnitBefore
                Globals.Ribbons.Ribbon1.obj.item("中行间距").item("SpaceAfter") = .SpaceAfter
                Globals.Ribbons.Ribbon1.obj.item("中行间距").item("SpaceBefore") = .SpaceBefore
            End With
            Globals.Ribbons.Ribbon1.保存配置（）
        End If
    End Sub
    Public Sub 保存大行间距配置()
        Dim returnValue = MsgBox("确认将大行间距设置为当前选中文本样式？", vbOKCancel + vbExclamation + vbDefaultButton2, "")
        If returnValue = 1 Then
            With oWord.Selection.ParagraphFormat
                Globals.Ribbons.Ribbon1.obj.item("大行间距").item("CharacterUnitLeftIndent") = .CharacterUnitLeftIndent
                Globals.Ribbons.Ribbon1.obj.item("大行间距").item("CharacterUnitRightIndent") = .CharacterUnitRightIndent
                Globals.Ribbons.Ribbon1.obj.item("大行间距").item("LineSpacing") = .LineSpacing
                Globals.Ribbons.Ribbon1.obj.item("大行间距").item("LineSpacingRule") = .LineSpacingRule
                Globals.Ribbons.Ribbon1.obj.item("大行间距").item("LeftIndent") = .LeftIndent
                Globals.Ribbons.Ribbon1.obj.item("大行间距").item("RightIndent") = .RightIndent
                Globals.Ribbons.Ribbon1.obj.item("大行间距").item("LineUnitAfter") = .LineUnitAfter
                Globals.Ribbons.Ribbon1.obj.item("大行间距").item("LineUnitBefore") = .LineUnitBefore
                Globals.Ribbons.Ribbon1.obj.item("大行间距").item("SpaceAfter") = .SpaceAfter
                Globals.Ribbons.Ribbon1.obj.item("大行间距").item("SpaceBefore") = .SpaceBefore
            End With
            Globals.Ribbons.Ribbon1.保存配置（）
        End If
    End Sub
    Public Sub 保存正文配置()
        Dim returnValue = MsgBox("确认将正文格式设置为当前选中文本样式？", vbOKCancel + vbExclamation + vbDefaultButton2, "")
        If returnValue = 1 Then
            SetMyStyle("正文")
            Globals.Ribbons.Ribbon1.保存配置（）
        End If
    End Sub
    Public Sub 保存页面配置()
        Dim returnValue = MsgBox("确认将页面设置格式设置为当前页面样式？", vbOKCancel + vbExclamation + vbDefaultButton2, "")
        If returnValue = 1 Then
            With oWord.ActiveDocument.Range.PageSetup
                Globals.Ribbons.Ribbon1.obj.item("页面设置").item("TopMargin") = .TopMargin
                Globals.Ribbons.Ribbon1.obj.item("页面设置").item("BottomMargin") = .BottomMargin
                Globals.Ribbons.Ribbon1.obj.item("页面设置").item("LeftMargin") = .LeftMargin
                Globals.Ribbons.Ribbon1.obj.item("页面设置").item("RightMargin") = .RightMargin
            End With
            Globals.Ribbons.Ribbon1.保存配置（）
        End If
    End Sub
End Module
